﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.IO;

namespace GBPVRLibrary.UtilityLibrary
{
    public class EmbeddedResourceReader
    {
        /// <summary>
        /// Gets the contents of an embedded text resource
        /// </summary>
        /// <param name="Assembly">the Assembly to load the Resource from</param>
        /// <param name="ResourceName">the full name of the Resource to read</param>
        /// <returns>the contents of the resource, or null if not found</returns>
        public static string GetTextResource(Assembly Assembly, string ResourceName)
        {
            try
            {
                using (TextReader reader = new StreamReader(Assembly.GetManifestResourceStream(ResourceName)))
                {
                    return reader.ReadToEnd();                    
                }
            }
            catch (Exception) { return null; }
        }

        /// <summary>
        /// Gets the contents of an embedded text resource
        /// </summary>
        /// <param name="ResourceName">the full name of the Resource to read</param>
        /// <returns>the contents of the resource, or null if not found</returns>
        public static string GetTextResourceFromExecutingAssmebly(string ResourceName)
        {
            return GetTextResource(Assembly.GetExecutingAssembly(), ResourceName);
        }
    }
}
